/*
 * Copyright 2015-2019 Evun Technology. 
 * 
 * This software is the confidential and proprietary information of
 * Evun Technology. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with evun.cn.
 */
package cn.evun.sweet.demo.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.ibatis.type.Alias;

import cn.evun.sweet.base.model.UserBase;
import cn.evun.sweet.base.util.UserContext;
import cn.evun.sweet.core.mybatis.general.RelationTable;

/**
 * 用户信息表对应的实体
 *
 * @author yangw
 * @since 1.0.0
 */
@Alias("user")
@Table(schema="U", name="sweet_demo_user")//别名'U'主要用于关联查询，必须指定，'name'不指定则将使用类名的驼峰转换形式作为表名
public class UserDo extends UserBase {
	
	//静态字段自动排除不予表字段映射
	private static final long serialVersionUID = 1L;
	
	public static final Integer USER_ROLE_ADMIN = 1;
	public static final Integer USER_ROLE_NORMAL = 2;
	
	@Column(name="user_sign") //默认可不使用，自动驼峰转换后映射
	private String userSign;
	@Column(name="user_role") //默认可不使用，自动驼峰转换后映射
	private Integer userRole;
	
	@Transient //不做表字段映射
	private Date createdonStart;
	@Transient //不做表字段映射
	private Date createdonEnd;
	
	@RelationTable(fkCol="tenantId", col="userTenantId")
	public TenantDo sweetDemoTenant;//属性名必须和关联类对应的表名的驼峰形式一致，以保证级联查询有效。  	
	
	@RelationTable(fkCol="orgId", col="userOrgId")
	public OrgDo sweetDemoOrg; //属性名必须和关联类对应的表名的驼峰形式一致，以保证级联查询有效。

	public String getUserSign() {
		return userSign;
	}

	public void setUserSign(String userSign) {
		this.userSign = userSign;
	}

	public Integer getUserRole() {
		return userRole;
	}

	public void setUserRole(Integer userRole) {
		this.userRole = userRole;
	}

	public TenantDo getSweetDemoTenant() {
		return sweetDemoTenant;
	}

	public void setSweetDemoTenant(TenantDo sweetDemoTenant) {
		this.sweetDemoTenant = sweetDemoTenant;
	}

	public OrgDo getSweetDemoOrg() {
		return sweetDemoOrg;
	}

	public void setSweetDemoOrg(OrgDo sweetDemoOrg) {
		this.sweetDemoOrg = sweetDemoOrg;
	}

	public Date getCreatedonStart() {
		return createdonStart;
	}

	public void setCreatedonStart(Date createdonStart) {
		this.createdonStart = createdonStart;
	}

	public Date getCreatedonEnd() {
		return createdonEnd;
	}

	public void setCreatedonEnd(Date createdonEnd) {
		this.createdonEnd = createdonEnd;
	}
	
	public UserDo initDefaultInfo(){
		if(this.userRole == null){
			this.setUserRole(3);
		}
		this.setUserPassword("7c4a8d09ca3762af61e59520943dc264");
		this.setUserForcemodifypsw(true);
		this.setUserCreatedon(new Date());
		this.setUserModifiedon(new Date());
		this.setUserTenantId(UserContext.getTenantId());
		this.setUserStatus(true);
		this.setUserIsdel(false);		
		return this;
	}

}
